<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文件上传</title>
	<script src="jquery-3.2.1.js"></script>
</head>
<body>

<form action="/file/upload" method="post" enctype="multipart/form-data">
	<input type="file" name="file">
	<input type="submit" value="表单上传">
</form>

<input type="file" id="file">
<input type="button" value="Ajax单文件上传" onclick="upload()">
<img alt="Ajax单文件上传" id="result">

<form id="files" action="/file/uploads" method="post" enctype="multipart/form-data">
	<input type="file" name="files" multiple>
	<input type="submit" value="Ajax多文件上传">
</form>
<script>
	function upload() {
		let file = $("#file")[0].files[0];
		let formData = new FormData();
		formData.append("file", file);
		$.ajax({
			type: 'post',
			url: '/file/upload',
			processData: false,// 不用给我处理成对象
			contentType: false,
			data: formData,
			success: function (res) {
				$("#result").attr("src", JSON.parse(res))
			}
		})
	}

</script>
</body>
</html>